package com.wuhuahe.learning.lagou.service.user.service.impl;

import com.wuhuahe.learning.lagou.service.dubbo.api.TokenService;
import com.wuhuahe.learning.lagou.service.dubbo.api.protol.UserToken;
import com.wuhuahe.learning.lagou.service.user.mapper.TokenMapper;

import com.wuhuahe.learning.lagou.service.user.pojo.Token;
import org.apache.dubbo.config.annotation.Service;


import javax.annotation.Resource;

@Service
public class TokenServiceImpl implements TokenService {

    @Resource
    private TokenMapper tokenMapper;


    @Override
    public long insertToken(UserToken userToken) {

        Token token = new Token();
        token.setEmail(userToken.getEmail());
        token.setToken(userToken.getToken());
        return tokenMapper.insertToken(token);
    }

    @Override
    public void updateToken(UserToken userToken) {
        Token token = new Token();
        token.setId(userToken.getId());
        token.setEmail(userToken.getEmail());
        token.setToken(userToken.getToken());
        tokenMapper.updateToken(token);

    }

    @Override
    public UserToken findByEmail(String email) {
        Token token = tokenMapper.findByEmail(email);
        UserToken userToken = new UserToken();
        userToken.setId(token.getId());
        userToken.setEmail(token.getEmail());
        userToken.setToken(token.getToken());
        return userToken;
    }
}
